package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.text.Annotation;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args)throws Exception {
        System.out.println("请输入类名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        Class<?> cls = Class.forName(name);
        Object o = cls.newInstance();
        if (cls.isAnnotationPresent(AutoRunClass.class)) {
            Method[] methods = cls.getDeclaredMethods();
            for (Method method : methods){
                if (method.isAnnotationPresent(AutoRunMethod.class)){
                    AutoRunMethod a = method.getAnnotation(AutoRunMethod.class);
                    int value = a.value();
                    for (int i = 0;i < value;++i){
                        method.invoke(o);
                    }
                }
            }
        }else {
            System.out.println("该类没有被AutoRunClass标注");
        }
    }
}
